//
//  TheOne_HeaderConfig.h
//  lTTheOne
//
//  Created by AA on 2024/1/21.
//

#ifndef TheOne_HeaderConfig_h
#define TheOne_HeaderConfig_h

#import "TXAdapter.h"
#import "UIColor+Custom.h"

#define ProductSever      0 /*********正式服务器*********/
#define DevelopSever      1 /*********测试服务器*********/

#if ProductSever
#define TESTING_LOG_SWITCH      0
#define DHFMAINURL @"http://api.theone-ca.cc"
#define PAYMAINURL @"http://103.101.205.126:6081"

#elif DevelopSever
#define TESTING_LOG_SWITCH      1
#define DHFMAINURL @"http://api.theone-ca.cc"
#define PAYMAINURL @"http://103.101.205.126:6081"
#endif


// 设备类型判断
#define KIs_IPAD [[[UIDevice currentDevice] model] isEqualToString:@"iPad"]
#define kIs_iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define kIS_iPhoneX ({BOOL isPhoneX = NO; if (@available(iOS 11.0, *)) { isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0; } (isPhoneX); })

// 屏幕尺寸
#define KScreenWidth [[UIScreen mainScreen] bounds].size.width
#define KScreenHeight [[UIScreen mainScreen] bounds].size.height
#define iphone_width [UIScreen mainScreen].bounds.size.width
#define iphone_height [UIScreen mainScreen].bounds.size.height

// 适配相关
#define KDefaultScreenWidth 375.0
#define KDefaultScreenHeight 812.0
#define KFitWidth(width) (width * KScreenWidth / KDefaultScreenWidth)
#define KFitHeight(height) (height * KScreenHeight / KDefaultScreenHeight)

#define KSizeScale 1
#define horvalue 2

//适配刘海屏--安全高度-状态栏
#define KStatusBarHeight \
({ \
    CGFloat height = 0.0; \
    if (@available(iOS 13.0, *)) { \
        UIWindowScene *activeScene = nil; \
        for (UIWindowScene *scene in [UIApplication sharedApplication].connectedScenes) { \
            if (scene.activationState == UISceneActivationStateForegroundActive) { \
                activeScene = scene; \
                break; \
            } \
        } \
        UIWindow *keyWindow = nil; \
        if (activeScene) { \
            for (UIWindow *window in activeScene.windows) { \
                if (window.isKeyWindow) { \
                    keyWindow = window; \
                    break; \
                } \
            } \
        } \
        if (keyWindow) { \
            height = keyWindow.safeAreaInsets.top; \
        } \
        if (height <= 0) { \
            height = [UIApplication sharedApplication].statusBarFrame.size.height; \
        } \
    } else { \
        height = [UIApplication sharedApplication].statusBarFrame.size.height; \
    } \
    (height); \
})

//适配刘海屏--安全高度-tabbar
#define KTabBarSafe_Height \
({ \
    CGFloat _h = 0.0; \
    BOOL _found = NO; \
    if (@available(iOS 13.0, *)) { \
        NSArray<UIScene *> *scenes = [UIApplication sharedApplication].connectedScenes.allObjects; \
        for (UIScene *scene in scenes) { \
            if (scene.activationState == UISceneActivationStateForegroundActive && \
                [scene isKindOfClass:UIWindowScene.class]) { \
                NSArray<UIWindow *> *windows = [(UIWindowScene *)scene windows]; \
                for (UIWindow *window in windows) { \
                    if (window.isKeyWindow) { \
                        _h = window.safeAreaInsets.bottom; \
                        _found = YES; \
                        break; \
                    } \
                } \
                if (_found) break; \
            } \
        } \
    } else { \
        _h = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom; \
    } \
    MAX(_h, 0); \
})

#define KNavBarHeight_Fixed     44
#define KTabBarHeight_Fixed     49
#define KNavBarHeight           (KStatusBarHeight+KNavBarHeight_Fixed)
#define KTabBarHeight           (KTabBarSafe_Height+KTabBarHeight_Fixed)

#define KsystemVersion [[UIDevice currentDevice] systemVersion]


// 颜色创建
#define HEXColor(_hex_) [UIColor colorWithHexString:_hex_]
#define HEXColor_alpha(HEXSTR , ALPHA) [UIColor colorWithHexString:HEXSTR alpha:ALPHA]
#define cust_Color(r,g,b,a) [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:a]
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define KUIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:1.0]
#define KUIColorFromRGBWithAlpha(rgbValue, ala) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:ala]

// 常用颜色
#define BacColor HEXColor(@"#161616")
#define KChatBacColor KUIColorFromRGB(0x161616)
#define mythetextcolor [UIColor blackColor]
#define unifiedColor cust_Color(122, 122, 218, 1)

// 字体定义
#define PingFangRegular(s)       [UIFont fontWithName:@"PingFangSC-Regular" size:s]
#define PingFangMedium(s)        [UIFont fontWithName:@"PingFangSC-Medium" size:s]
#define PingFangBold(s)          [UIFont fontWithName:@"PingFangSC-Semibold" size:s]
#define FontSSYZT(s)             [UIFont fontWithName:@"098-" size:s] //上首元正体

#define KFont_M(value) [UIFont fontWithName:@"pingFangSC-Medium" size:value * KSizeScale]
#define KFont_B(value) [UIFont fontWithName:@"PingFangSC-Bold" size:value * KSizeScale]
#define KFont_N(value) [UIFont fontWithName:@"PingFangSC-Regular" size:value * KSizeScale]
#define KFont_SB(value) [UIFont fontWithName:@"PingFangSC-Semibold" size:value * KSizeScale]


#define APP_NAME ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"])
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define APP_BUILD ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"])

#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ||[str isEqualToString:@""]? YES : NO )
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
#define kObjectIsEmpty(_object) (_object == nil|| [_object isKindOfClass:[NSNull class]]|| ([_object respondsToSelector:@selector(length)] &[(NSData *)_object length] == 0)|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

// 弱引用
#define WEAKSELF __weak typeof(self) weakSelf = self;

// NSUserDefaults
#define defalut NSUserDefaults *userDefalut = [NSUserDefaults standardUserDefaults];

// 登录状态
#define UserISLogin @"UserISLogin" //是否登录
// 用户信息
#define UserInfo @"UserInfo"

// 国际化
#define LocalMyString(key) NSLocalizedStringFromTable(key, @"Localizable", key)
#define LocalString(title) NSLocalizedString(title, nil)

// View圆角
#define KViewBorderRadius(View, Radius, Width, Color) [View.layer setCornerRadius:(Radius)]; [View.layer setMasksToBounds:YES]; [View.layer setBorderWidth:(Width)]; [View.layer setBorderColor:[Color CGColor]]
#define KViewRadius(View, Radius) [View.layer setCornerRadius:(Radius)]; [View.layer setMasksToBounds:YES]

// WebSocket通知
#define KWebSocketReceiveMessageName @"socketReceiveMessageNoti"

#define kDateFormatDefault            @"yyyy-MM-dd HH:mm:ss"
#define kDateFormat_yyMdHm            @"yy-MM-dd HH:mm"
#define kDateFormat_yyyyMdHm          @"yyyy-MM-dd HH:mm"
#define kDateFormat_yMd               @"yyyy-MM-dd"
#define kDateFormat_MdHms             @"MM-dd HH:mm:ss"
#define kDateFormat_MdHm              @"MM-dd HH:mm"
#define kDateFormatTime               @"HH:mm:ss"
#define kDateFormat_Hm                @"HH:mm"
#define kDateFormat_Md                @"MM-dd"
#define kDateFormat_yyMd              @"yy-MM-dd"
#define kDateFormat_YYMMdd            @"yyyyMMdd"
#define kDateFormat_yyyyMdHms         @"yyyyMMddHHmmss"
#define kDateFormat_yyyyMdHmsS        @"yyyy-MM-dd HH:mm:ss.SSS"
#define kDateFormat_yyyyMMddHHmmssSSS @"yyyyMMddHHmmssSSS"

#endif /* TheOne_HeaderConfig_h */
